package com.ruoyi.web.controller.mtproject;

import java.util.List;

import com.ruoyi.domain.DunApplication;
import com.ruoyi.system.domain.ProCreateBuilding;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.MtProBuild;
import com.ruoyi.service.IMtProBuildService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维保项目创建Controller
 *
 * @author ruoyi
 * @date 2020-07-04
 */
@Controller
@RequestMapping("/ruoyi/build")
public class MtProBuildController extends BaseController
{
    private String prefix = "ruoyi/build";

    @Autowired
    private IMtProBuildService mtProBuildService;

    @RequiresPermissions("ruoyi:build:view")
    @GetMapping()
    public String build()
    {
        return prefix + "/build";
    }

    /**
     * 查询维保项目创建列表
     */
    @RequiresPermissions("ruoyi:build:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MtProBuild mtProBuild)
    {
        startPage();
        List<MtProBuild> list = mtProBuildService.selectMtProBuildList(mtProBuild);
        return getDataTable(list);
    }

    /**
     * 导出维保项目创建列表
     */
    @RequiresPermissions("ruoyi:build:export")
    @Log(title = "维保项目创建", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MtProBuild mtProBuild)
    {
        List<MtProBuild> list = mtProBuildService.selectMtProBuildList(mtProBuild);
        ExcelUtil<MtProBuild> util = new ExcelUtil<MtProBuild>(MtProBuild.class);
        return util.exportExcel(list, "build");
    }

    /**
     * 新增维保项目创建
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存维保项目创建
     */
    @RequiresPermissions("ruoyi:build:add")
    @Log(title = "维保项目创建", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MtProBuild mtProBuild)
    {
        return toAjax(mtProBuildService.insertMtProBuild(mtProBuild));
    }

    /**
     * 修改维保项目创建
     */
    @GetMapping("/edit/{mtId}")
    public String edit(@PathVariable("mtId") Long mtId, ModelMap mmap)
    {
        MtProBuild mtProBuild = mtProBuildService.selectMtProBuildById(mtId);
        mmap.put("mtProBuild", mtProBuild);
        return prefix + "/edit";
    }

    /**
     * 修改保存维保项目创建
     */
    @RequiresPermissions("ruoyi:build:edit")
    @Log(title = "维保项目创建", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MtProBuild mtProBuild)
    {
        return toAjax(mtProBuildService.updateMtProBuild(mtProBuild));
    }

    /**
     * 删除维保项目创建
     */
    @RequiresPermissions("ruoyi:build:remove")
    @Log(title = "维保项目创建", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mtProBuildService.deleteMtProBuildByIds(ids));
    }

    //导出所有项目工程款明细
    @Log(title = "项目工程款", businessType = BusinessType.EXPORT)
    @RequiresPermissions("ruoyi:build:exports")
    @PostMapping("/exports")
    @ResponseBody
    public AjaxResult exports(MtProBuild mtProBuild)
    {
//        List<MtProBuild> list = mtProBuildService.selectAllexport(mt);
//        ExcelUtil<MtProBuild> util = new ExcelUtil<MtProBuild>(MtProBuild.class);
//        return util.exportExcel(list, "维保项目明细");
        List<MtProBuild> list = mtProBuildService.selectexport(mtProBuild);
        ExcelUtil<MtProBuild> util = new ExcelUtil<MtProBuild>(MtProBuild.class);
        return util.exportExcel(list, "维保项目列表");
    }

    /**
     * 表格细节视图
     */
    @GetMapping("/detail/{mtId}")
    public String detail(@PathVariable("mtId") Long mtId, ModelMap map) {
        MtProBuild mtProBuild = mtProBuildService.selectMtProBuildById(mtId);
        map.put("mtProBuild", mtProBuild);
        return prefix + "/detail";
    }

}
